package com.fywsy.fyweb.strategy;

import com.fywsy.fyweb.entity.SendItem;
import com.fywsy.fyweb.repository.StrategyResp;
import com.fywsy.fyweb.utils.RestTemplateUtil;
import com.google.gson.Gson;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

/**
 * 游戏后台实现类
 * 注解gameId对应数据库游戏id
 * 注解GongnengMethod对应数据库功能id
 */
@Component
@GameId(6)
public class ALiangTianGameStrategy extends BaseGameStrategy {

    public static final String URL = "http://110.40.83.197:8081/gm/user/gmquery.php";

    /**
     * http://110.40.83.197:8081/gm/user/gmquery.php
     * type: mail
     * checknum: diyao88
     * uid: m666661
     * item: 0
     * num: 11
     * qu: 1
     * @param item
     * @return
     */

    @GongnengMethod(601)
    public String mail(SendItem item) {
        MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
        params.add("type", "mail");
        params.add("checknum", "diyao88");
        params.add("qu", "1");
        params.add("uid", item.uid);
        params.add("item", item.itemId);
        params.add("num", item.number);
        String resp = RestTemplateUtil.sendPostForm(URL, params);
        try {
            StrategyResp strategyResp = new Gson().fromJson(resp, StrategyResp.class);
            return strategyResp.info;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return resp;
    }

    @GongnengMethod(602)
    public String day(SendItem item) {
        return mail(item);
    }

    @GongnengMethod(2)
    public String pay(SendItem item) {
        System.out.println("发送充值：金额：");
        return "充值已发送，金额：";
    }

    @GongnengMethod(4)
    public String cleat(SendItem item) {
        System.out.println("清除成功");
        return "清除成功";
    }
}

